<template>
	<view class=" ">

		<view class="bg-white">
			<scroll-view scroll-y="true" class="scroll-Y">
				<uni-card>
					<view class="p-t-b-10">
						<button @click="on_add(0)" type="primary" size="mini">新增</button>
					</view>
					<uni-table border stripe type="selection" :type="'2'" @selection-change="selectionData">
						<uni-tr>
							<uni-th align="center" width="30px">id</uni-th>
							<uni-th align="center">手机号</uni-th>
							<uni-th align="center">账号</uni-th>
							<uni-th align="center">名称</uni-th>
							<uni-th align="center">最近登陆</uni-th>
							<uni-th align="center">最后ip</uni-th>
							<uni-th align="center">角色</uni-th>
							<uni-th align="center" width="130px">管理</uni-th>
						</uni-tr>
						<uni-tr v-for="(vo,index) in list" :key="index">
							<uni-td align="center">
								{{vo.id}}
							</uni-td>
							<uni-td align="center">
								{{vo.tel}}
							</uni-td>
							<uni-td align="center">
								{{vo.account}}
							</uni-td>
							<uni-td align="center">
								{{vo.nickname}}
							</uni-td>
							<uni-td align="center">
								<view v-if="vo.end_time>0">
									{{vo.end_time|getTime}}
								</view>
							</uni-td>
							<uni-td align="center">{{vo.lastip}}</uni-td>
							<uni-td align="center">
								{{vo.role_name}}
							</uni-td>
							<uni-td align="center">
								<view class="">
									<button @click="on_add(vo.id)" type="primary" size="mini">编辑</button>
								</view>
								<view class="">
									<button @click="on_del(vo.id,index)" type="warn" size="mini">删除</button>
								</view>
							</uni-td>
						</uni-tr>
					</uni-table>
					<template v-slot:actions>
						<view style="width: 100%;">
							<uni-pagination @change="getPage" show-icon="true" :total="total" current="1"
								style="float: left;margin-bottom: 10px;"></uni-pagination>
						</view>
					</template>
				</uni-card>
			</scroll-view>

		</view>


		<edit ref="component_edit" @confirm="confirm_edit">
		</edit>
	</view>
</template>

<script>
	import edit from './edit.vue';

	export default {
		components: {
			edit,
		},
		data() {
			return {
				list: [],
				last_page: 0,
				total: 0,
				page: 1,

				fromsData: {
					user_name: '',
					email: ''
				},


			}
		},
		onLoad(on) {

			this.init();

		},
		methods: {
			confirm_edit() {
				this.init()
			},
			on_add(id) {
				this.id = id;
				this.$refs.component_edit.init(id)
			},
			on_del(id, index) {
				var that = this;
				uni.showModal({
					title: '提示',
					content: '确认要删除吗？',
					success: function(res) {
						if (res.confirm) {
							that.ajax_del(id, index);
						}
					}
				});
			},

			async ajax_del(id, index) {
				var that = this;
				let requestParams = {
					id: id
				};
				const ret = await this.Banmikeji.admin_admin_del(requestParams);
				uni.showToast({
					title: ret.msg,
					icon: 'none'
				})
				if (ret.status == 200) {
					this.init();

				}
			},
			getPage(id) {
				this.page = id.current;
				this.init()
			},
			async init() {
				var that = this;
				let requestParams = {};
				const ret = await this.Banmikeji.role_role_list(requestParams);
				if (ret.status == 200) {
					this.list = ret.data.list.data;
					this.total = ret.data.list.total;
				}
			},


		}
	}
</script>

<style>
	.feng {
		color: red;
	}
</style>